package com.flying.client.ui;

import com.flying.client.network.NetworkClient;
import com.flying.client.network.NetworkProvider;
import com.flying.client.network.SystemNetwork;
import com.flying.client.network.SystemNetwork.NetworkType;
import com.flying.client.network.msg.OWMsg;
import com.flying.client.utils.Logger;
import com.flying.cn.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {
	private static final Logger logger = Logger.getLogger(MainActivity.class.getName());
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        checkNetworkType();
        
        findViewById(R.id.btn_start).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				//NetworkClient client = new NetworkClient("192.168.0.123", 10234);
				//client.connect();
			}
		});
        
        findViewById(R.id.btn_checkNetwork).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				checkNetworkType();
			}
		});
        
        findViewById(R.id.btn_send).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				//TestOWMsg msg = new TestOWMsg((short)1,null);
				OWMsg wMsg = InitSessionHandler.createWMsg();
				logger.debug("msg.isNeedFeedBack="+wMsg.isNeedFeedback());
				//boolean isSuccess = NetworkProvider.getInstance().send(wMsg);
				//logger.debug("btn_send.OnClick send.Success="+isSuccess);
			}
		});
    }
    
    public void checkNetworkType()
    {
    	NetworkType type = SystemNetwork.getCurrentSystemNetwork(MainActivity.this);
		
		TextView textView = (TextView)findViewById(R.id.txt_network);
		
		String strNetType = "";
		
		if ( type == NetworkType.NoNetwork)
		{
			strNetType = "Nonetwork";
		}
		else if (type == NetworkType.CMNET)
		{
			strNetType = "cmnet";
		} else if ( type == NetworkType.CMWAP)
		{
			strNetType = "cmwap";
		} else if ( type == NetworkType.Wifi)
		{
			strNetType = "wifi";
		}
		textView.setText("strNetType="+strNetType);
    }
}